package com.cate.mapper;

import com.cate.annotation.AutoFill;
import com.cate.enums.OperationType;
import com.cate.pojo.entity.Category;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 插入数据
     * @param record
     * @return
     */
    @AutoFill(OperationType.INSERT)
    int insert(Category record);

    /**
     * 通过id获得分类信息
     * @param categoryId
     * @return
     */
    @Select("select * from category where id=#{categoryId}")
    Category getById(Long categoryId);

    /**
     * 分页查询
     * @param name
     * @param type
     * @return
     */
    Page<Category> selectPage(String name,Integer type);

    /**
     * 查询类型下的分类
     * @param type
     * @return
     */
    List<Category> selectList(Integer type);

    /**
     * 更新分类
     * @param record
     * @return
     */
    int update(Category record);

    /**
     * 删除分类
     * @param categoryId
     * @return
     */
    @Delete("delete from category where id = #{categoryId}")
    int deleteById(Long categoryId);
}
